package org.abstractmeta.commandify.core.command.collection;

import org.abstractmeta.commandify.command.Commands;
import org.abstractmeta.commandify.core.command.AbstractConstructorCommand;
import org.abstractmeta.commandify.core.command.CommandifyCollection;

import java.util.HashSet;
import java.util.Set;

/**
 * Represents a set which implement commandify.
 * This enables all mutable collection method calls being encapsulated as method commands.
 * If collection value implements commandify then as long as it is possible to build cloned version build, it will be used
 * instead of actual value.
 */
public class CommandifySet<T> extends CommandifyCollection<T> implements Set<T> {

    protected final Set<T> set;


    public CommandifySet(Class type, Set<T> set) {
            super(type, set);
            this.set = set;
        }

    @SuppressWarnings("unchecked")
      protected void addConstructorCommand() {
          Commands commands = getCommands();
          commands.setConstructorCommand(new AbstractConstructorCommand<Set<T>>() {
              @Override
              public Set<T> execute() {
                  return new HashSet<T>();
              }
          });
      }


}
